home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / games_d / rtanksrc.zip / INTERP.C < prev    next >
C/C++ Source or Header  |  1995-03-07  |  20KB  |  730 lines

  1. /**--------------------------------------------------------------
  2.  **
  3.  **--------------------------------------------------------------
  4.  ** MODULE     : interp.c
  5.  ** PURPOSE    : <t> Interprete compiler output
  6.  ** PROGRAMMER : Sandy
  7.  ** START DATE : 11/29/1988 11:55:11
  8.  ** DESCRIPTION:
  9.  **            :
  10.  **            :
  11.  **==============================================================
  12.  **/
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <dos.h>
  17. #include <conio.h>
  18. #include <math.h>
  19. #include <dtypes.h>
  20. #include <string.h>
  21.  
  22. #include "shop.h"
  23. #include "interp.h"
  24. #include "graph.h"
  25. #include "bullet.h"
  26.  
  27. #include "tconfig.h"
  28.  
  29. #define  BASERANGE    50
  30. #define  MAX_X        75
  31. #define  MAX_Y        43
  32.  
  33. BYTE ps1[] = {
  34.                0x02, 0x04,    /* Sizex, Sizey */
  35.                0x03, 0xc0, 0x0b, 0xe0, 0x23, 0xc8, 0x23, 0xc8,
  36.                0x20, 0x08, 0x20, 0x08, 0x0a, 0xa0, 0x00, 0x00
  37. };
  38. BYTE ps2[] = {
  39.                0x02, 0x04,    /* Sizex, Sizey */
  40.                0x00, 0x03, 0x0a, 0xBC, 0x20, 0xF8, 0x23, 0xE8,
  41.                0x20, 0x08, 0x20, 0x08, 0x0a, 0xa0, 0x00, 0x00
  42. };
  43. BYTE ps3[] = {
  44.                0x02, 0x04,    /* Sizex, Sizey */
  45.                0x00, 0x00, 0x0a, 0xa0, 0x20, 0x08, 0x20, 0xFF,
  46.                0x20, 0xFF, 0x20, 0x08, 0x0a, 0xa0, 0x00, 0x00
  47. };
  48. BYTE ps4[] = {
  49.                0x02, 0x04,    /* Sizex, Sizey */
  50.                0x00, 0x00, 0x0a, 0xa0, 0x20, 0x08, 0x20, 0x08,
  51.                0x23, 0xE8, 0x20, 0xF8, 0x0a, 0xBC, 0x00, 0x03
  52. };
  53. BYTE ps5[] = {
  54.                0x02, 0x04,    /* Sizex, Sizey */
  55.                0x00, 0x00, 0x0a, 0xa0, 0x20, 0x08, 0x20, 0x08,
  56.                0x23, 0xc8, 0x23, 0xc8, 0x0b, 0xe0, 0x03, 0xc0
  57. };
  58. BYTE ps6[] = {
  59.                0x02, 0x04,    /* Sizex, Sizey */
  60.                0x00, 0x00, 0x0a, 0xa0, 0x20, 0x08, 0x20, 0x08,
  61.                0x23, 0xC8, 0x2F, 0x08, 0x3C, 0xa0, 0xF0, 0x00
  62. };
  63. BYTE ps7[] = {
  64.                0x02, 0x04,    /* Sizex, Sizey */
  65.                0x00, 0x00, 0x0a, 0xa0, 0x20, 0x08, 0xFF, 0x08,
  66.                0xFF, 0x08, 0x20, 0x08, 0x0a, 0xa0, 0x00, 0x00
  67. };
  68. BYTE ps8[] = {
  69.                0x02, 0x04,    /* Sizex, Sizey */
  70.                0xF0, 0x00, 0x3C, 0xa0, 0x2F, 0x08, 0x23, 0xC8,
  71.                0x20, 0x08, 0x20, 0x08, 0x0a, 0xa0, 0x00, 0x00
  72. };
  73. BYTE noblk[] = {
  74.                          0x02, 0x04,    /* Sizex, Sizey */
  75.                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  76.                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  77. };
  78.  
  79. BYTE ps0[] = {
  80.                          0x02, 0x04,    /* Sizex, Sizey */
  81.                          0x00, 0x00, 0x0a, 0xa0, 0x20, 0x08, 0x20, 0x08,
  82.                          0x20, 0x08, 0x20, 0x08, 0x0a, 0xa0, 0x00, 0x00
  83. };
  84.  
  85. char far *blank;
  86.  
  87. extern void CALLASM(int x, int y, char far *buf);
  88. extern void SETMODE(void);
  89.  
  90. BOT players[10];
  91. int debug;
  92. int nplayers;
  93. BOOL b_goodread;
  94.  
  95. BYTE field[MAX_X][MAX_Y];
  96.  
  97. #include "code.h"
  98.  
  99. /*<f>----------------------------------------
  100.  * FUNCTION: <s> void v_do_arena(PSTR s[])
  101.  * PURPOSE : Mass combat function
  102.  *         :
  103.  * CREATION: 12/05/1988 14:17:44
  104.  */
  105. void v_do_arena(PSTR s[])
  106. {
  107. FILE *fp;
  108. int a;
  109. char temp[50];
  110. char config[50];
  111.  
  112.    randomize();
  113.  
  114.    v_init_playfield();
  115.  
  116.    for (a=0; a<10; a++) {
  117.       strcpy(temp,s[a+1]);
  118.       strcpy(config,s[a+1]);
  119.       strcat(temp,".BIN");
  120.       strcat(config,".DAT");
  121.       if ((*s[a+1]!=' ') && ((fp=fopen(temp,"rb"))!=NULL)) {
  122.  
  123.          fclose(fp);
  124.  
  125.          if ((fp=fopen(config,"rb"))!=NULL) {
  126.  
  127.             fclose(fp);
  128.  
  129.             v_init_bot(&players[a]);
  130.  
  131.             b_goodread=FALSE;
  132.  
  133.             v_load_file(temp, &players[a]);
  134.  
  135.             v_read_tank_from_disk(config,&players[a].tank_config);
  136.  
  137.             if (!b_goodread)
  138.                players[a].active=FALSE;
  139.             else
  140.                players[a].active=TRUE;
  141.  
  142.          } else players[a].active=FALSE;
  143.       } else players[a].active=FALSE;
  144.    }
  145.  
  146.    blank=noblk;  debug=0;
  147.    v_init_bullets();
  148.  
  149.    SETMODE();
  150.    v_draw_screen("ARENA BATTLE");
  151.  
  152.    printf("%u",coreleft());
  153.  
  154.    for (a=0; a<10; a++)
  155.       v_draw_player(&players[a]);
  156.  
  157.    while (!kbhit()) {
  158.       for (a=0; a<10; a++)
  159.          if (players[a].active)
  160.             v_interprete(&players[a]);
  161.       v_move_bullets();
  162.    }
  163.  
  164.    a=getkey();
  165.  
  166.    for (a=0; a<10; a++)
  167.       v_free_interpreter_ram(&players[a]);
  168.  
  169.    textmode(2);
  170. } /* void v_do_arena(PSTR s[]) */
  171.  
  172. /*<f>----------------------------------------
  173.  * FUNCTION: <s> void v_interp_main(PSTR s)
  174.  * PURPOSE : Program start
  175.  *         :
  176.  * CREATION: 11/29/1988 11:56:18
  177.  */
  178. void v_interp_main(PSTR s)
  179. {
  180. int a;
  181.  
  182.    debug=1;
  183.  
  184.    v_init_playfield();
  185.  
  186.    v_init_bot(&players[0]);
  187.  
  188.    b_goodread=FALSE;
  189.  
  190.    v_load_file(s, &players[0]);
  191.  
  192.    if (!b_goodread)
  193.       return;
  194.  
  195.    blank=noblk;
  196.  
  197.    SETMODE();
  198.    v_draw_screen(s);
  199.    v_draw_player(&players[0]);
  200.  
  201.    v_init_bullets();
  202.  
  203.    while (!kbhit()) {
  204.       v_interprete(&players[0]);
  205.       v_move_bullets();
  206.    }
  207.  
  208.    a=getkey();
  209.  
  210.    v_free_interpreter_ram(&players[0]);
  211.  
  212.    textmode(2);
  213.  
  214. } /* void v_interp_main(PSTR s) */
  215.  
  216. /*<f>----------------------------------------
  217.  * FUNCTION: <s> void v_load_file(PSTR s, p_BOT bot)
  218.  * PURPOSE : Load in a compiler binary file
  219.  *         :
  220.  * CREATION: 11/29/1988 11:58:11
  221.  */
  222. void v_load_file(PSTR s, p_BOT bot)
  223. {
  224. int a;
  225. FILE *fp;
  226.  
  227.    if ((fp=fopen(s,"rb"))==NULL) {
  228.       b_goodread=FALSE;
  229.       return;
  230.    }
  231.  
  232.    bot->fsize=getw(fp);
  233.    for (a=0; a<bot->fsize; a++) {
  234.        if (bot->nlines>MAXLINES) {
  235.           printf("Too many lines for interpreter\n");
  236.           exit(1);
  237.        }
  238.  
  239.       if ((bot->line[bot->nlines] = (p_ZLINE) malloc(sizeof(ZLINE)))==NULL) {
  240.          printf("Cannot malloc ram for tank code\n");
  241.          exit(1);
  242.       }
  243.       bot->line[bot->nlines]->n_command     =getw(fp);
  244.       bot->line[bot->nlines]->pline         =getw(fp);
  245.       bot->line[bot->nlines]->arg1.n_ArgType=getw(fp);
  246.       bot->line[bot->nlines]->arg1.n_value  =getw(fp);
  247.       bot->line[bot->nlines]->arg2.n_ArgType=getw(fp);
  248.       bot->line[bot->nlines]->arg2.n_value  =getw(fp);
  249.       bot->line[bot->nlines]->arg3.n_ArgType=getw(fp);
  250.       bot->line[bot->nlines]->arg3.n_value  =getw(fp);
  251.  
  252.       bot->nlines++;
  253.    }
  254.    fclose(fp);
  255.    b_goodread=TRUE;
  256. } /* void v_load_file(PSTR s, p_BOT bot) */
  257.  
  258. /*<f>----------------------------------------
  259.  * FUNCTION: <s> void v_init_bot(p_BOT pbot)
  260.  * PURPOSE : Initilize a bot
  261.  *         :
  262.  * CREATION: 11/29/1988 12:24:40
  263.  */
  264. void v_init_bot(p_BOT pbot)
  265. {
  266. int a;
  267.  
  268.    pbot->bax=1+(rand() % MAX_X);
  269.    pbot->bay=1+(rand() % MAX_Y);
  270.    pbot->bx=1+pbot->bax;
  271.    pbot->by=(pbot->bay<<1)+6;
  272.  
  273.    memset(pbot->vars,0,sizeof(int)*100);
  274.    for (a=0; a<MAXLINES; a++)
  275.       pbot->line[a]=NULL;
  276.  
  277.    pbot->cdir=pbot->gdir=1;
  278.    pbot->nlines=0;
  279.    pbot->cline=0;
  280.    pbot->ready=FALSE;
  281.    pbot->depth=0;
  282.  
  283.    pbot->pic[1]=ps1;
  284.    pbot->pic[2]=ps2;
  285.    pbot->pic[3]=ps3;
  286.    pbot->pic[4]=ps4;
  287.    pbot->pic[5]=ps5;
  288.    pbot->pic[6]=ps6;
  289.    pbot->pic[7]=ps7;
  290.    pbot->pic[8]=ps8;
  291.  
  292. } /* void v_init_bot(p_BOT pbot) */
  293.  
  294. /*<f>----------------------------------------
  295.  * FUNCTION: <s> void v_interprete(p_BOT p)
  296.  * PURPOSE : Interprete compiler code
  297.  *         :
  298.  * CREATION: 11/29/1988 12:34:43
  299.  */
  300. void v_interprete(p_BOT p)
  301. {
  302. p_ZLINE cl;
  303. BOOL   next;
  304.  
  305.    if (debug==0)
  306.       delay(5);
  307.  
  308.    if (p->cline>p->nlines) {
  309.       printf("Gone beyond program end @%d of %d\n",p->cline,p->nlines);
  310.       exit(1);
  311.    }
  312.  
  313.    cl=p->line[p->cline];
  314.  
  315.    next=TRUE;
  316.    switch (cl->n_command) {
  317.       case _WHEREX  : v_store(p, &cl->arg1,p->bax);
  318.                       break;
  319.  
  320.       case _WHEREY  : v_store(p, &cl->arg1,p->bay);
  321.                       break;
  322.  
  323.       case _RADAR   : if (p->tank_config.extrasType[RADAR]>0)
  324.                          v_store(p, &cl->arg1, n_check_radar(p) );
  325.                       break;
  326.  
  327.       case _SCAN    : v_store(p, &cl->arg1,
  328.                            n_check_scan(p,n_get_arg(p,&cl->arg2)));
  329.                       break;
  330.  
  331.       case _CGDIR   : v_store(p, &cl->arg1,p->gdir);
  332.                       break;
  333.  
  334.       case _CTDIR   : v_store(p, &cl->arg1,p->cdir);
  335.                       break;
  336.  
  337.       case _LEFT    : p->cdir--;
  338.                       if (p->cdir==0) p->cdir=8;
  339.                       break;
  340.  
  341.       case _RIGHT   : p->cdir++;
  342.                       if (p->cdir==9) p->cdir=1;
  343.                       break;
  344.  
  345.       case _GLEFT   : p->gdir--;
  346.                       if (p->gdir==0) p->gdir=8;
  347.                       v_redraw_player(p);
  348.                       break;
  349.  
  350.       case _GRIGHT  : p->gdir++;
  351.                       if (p->gdir==9) p->gdir=1;
  352.                       v_redraw_player(p);
  353.                       break;
  354.  
  355.       case _LOADED  : v_store(p, &cl->arg1,p->ready);
  356.                       break;
  357.  
  358.       case _MOVE    : p->obx=p->bx; p->oby=p->by;
  359.                       p->obax=p->bax; p->obay = p->bay;
  360.                       v_ido_move(p);
  361.                       v_erase_player(p);
  362.                       v_draw_player(p);
  363.                       break;
  364.  
  365.       case _FIRE    : v_shoot(p);
  366.                       break;
  367.  
  368.       case _JUMP    : p->cline=n_get_arg(p,&cl->arg1);
  369.                       next=FALSE;
  370.                       break;
  371.  
  372.       case _CALL    : v_do_call(p,&cl->arg1);
  373.                       next=FALSE;
  374.                       break;
  375.  
  376.       case _RETURN  : v_do_return(p);
  377.                       break;
  378.  
  379.       case _JUMPLESS: if (n_get_arg(p,&cl->arg1) < n_get_arg(p,&cl->arg2)) {
  380.                          p->cline=n_get_arg(p,&cl->arg3);
  381.                          next=FALSE;
  382.                       }
  383.                       break;
  384.  
  385.       case _JUMPEQ  : if (n_get_arg(p,&cl->arg1) == n_get_arg(p,&cl->arg2)) {
  386.                          p->cline=n_get_arg(p,&cl->arg3);
  387.                          next=FALSE;
  388.                       }
  389.                       break;
  390.  
  391.       case _JUMPNEQ : if (n_get_arg(p,&cl->arg1) != n_get_arg(p,&cl->arg2)) {
  392.                          p->cline=n_get_arg(p,&cl->arg3);
  393.                          next=FALSE;
  394.                       }
  395.                       break;
  396.  
  397.       case _JUMPGRT : if (n_get_arg(p,&cl->arg1) > n_get_arg(p,&cl->arg2)) {
  398.                          p->cline=n_get_arg(p,&cl->arg3);
  399.                          next=FALSE;
  400.                       }
  401.                       break;
  402.  
  403.       case _SET     : v_store(p,&cl->arg1,n_get_arg(p,&cl->arg2));
  404.                       break;
  405.  
  406.       case _ADD     : v_store(p,&cl->arg1,
  407.                            n_get_arg(p,&cl->arg1)+n_get_arg(p,&cl->arg2)
  408.                       );
  409.                       break;
  410.  
  411.       case _RAND    : v_store(p,&cl->arg1,1+(rand() % n_get_arg(p,&cl->arg2)));
  412.                       break;
  413.  
  414.    }
  415.    if (next) p->cline++;
  416. } /* void v_interprete(p_BOT p) */
  417.  
  418. /*<f>----------------------------------------
  419.  * FUNCTION: <s> void v_store(p_BOT pb, p_ZARG pa, int n)
  420.  * PURPOSE : Store constant N in argument PA
  421.  *         :
  422.  * CREATION: 11/29/1988 12:41:59
  423.  */
  424. void v_store(p_BOT pb, p_ZARG pa, int n)
  425. {
  426.    if (pa->n_ArgType!=SYMBOL) {
  427.       printf("Assignment destination must be a symbol, line %d\n",pb->line[pb->cline]->pline);
  428.       exit(1);
  429.    }
  430.    pb->vars[pa->n_value]=n;
  431. } /* void v_store(p_BOT pb,p_ZARG pa, int n) */
  432.  
  433. /*<f>----------------------------------------
  434.  * FUNCTION: <s> int n_get_arg(p_BOT pbot, p_ZARG p)
  435.  * PURPOSE : Return the value of an argument
  436.  *         :
  437.  * CREATION: 11/29/1988 12:56:51
  438.  */
  439. int n_get_arg(p_BOT pbot, p_ZARG p)
  440. {
  441.    if (p->n_ArgType==SYMBOL)
  442.       return (pbot->vars[p->n_value]);
  443.    else if (p->n_ArgType==CONSTANT)
  444.       return p->n_value;
  445.    else return p->n_value;
  446. } /* int n_get_arg(p_BOT pbot, p_ZARG p) */
  447.  
  448. /*<f>----------------------------------------
  449.  * FUNCTION: <s> void v_ido_move(p_BOT p)
  450.  * PURPOSE : Move in current direction
  451.  *         :
  452.  * CREATION: 11/29/1988 13:01:43
  453.  */
  454. void v_ido_move(p_BOT p)
  455. {
  456. int hx,hy, hx1, hy1;
  457.    hx =p->bx;  hy =p->by;
  458.    hx1=p->bax; hy1=p->bay;
  459.  
  460.    switch (p->cdir) {
  461.       case 1 : if (p->bay>1)  {p->bay--; p->by-=2; }
  462.                break;
  463.  
  464.       case 2 : if (p->bax<MAX_X) {p->bax++; p->bx++;  }
  465.                if (p->bay>1)  {p->bay--; p->by-=2; }
  466.                break;
  467.  
  468.       case 3 : if (p->bax<MAX_X) {p->bax++; p->bx++;  }
  469.                break;
  470.  
  471.       case 4 : if (p->bax<MAX_X) {p->bax++; p->bx++;  }
  472.                if (p->bay<MAX_Y) {p->bay++; p->by+=2; }
  473.                break;
  474.  
  475.       case 5 : if (p->bay<MAX_Y) {p->bay++; p->by+=2; }
  476.                break;
  477.  
  478.       case 6 : if (p->bay<MAX_Y) {p->bay++; p->by+=2; }
  479.                if (p->bax> 1) {p->bax--; p->bx--;  }
  480.                break;
  481.  
  482.       case 7 : if (p->bax> 1) {p->bax--; p->bx--;  }
  483.                break;
  484.  
  485.       case 8 : if (p->bax> 1) {p->bax--; p->bx--;  }
  486.                if (p->bay> 1) {p->bay--; p->by-=2; }
  487.                break;
  488.    }
  489.    if (field[p->bx][p->by]>=100) {
  490.       p->bx=hx;   p->by =hy;
  491.       p->bax=hx1; p->bay=hy1;
  492.    }
  493. } /* void v_ido_move(p_BOT p) */
  494.  
  495. /*<f>----------------------------------------
  496.  * FUNCTION: <s> void v_do_call(p_BOT pb, p_ZARG pa)
  497.  * PURPOSE : Call subroutine at PA
  498.  *         :
  499.  * CREATION: 11/29/1988 14:21:52
  500.  */
  501. void v_do_call(p_BOT pb, p_ZARG pa)
  502. {
  503.    if (pb->depth>19) {
  504.       printf("Too many GOSUB's\n");
  505.       exit(1);
  506.    }
  507.  
  508.    pb->gosub[pb->depth++]=pb->cline;
  509.    pb->cline=n_get_arg(pb,pa);
  510.  
  511. } /* void v_do_call(p_BOT pb, p_ZARG pa) */
  512.  
  513. /*<f>----------------------------------------
  514.  * FUNCTION: <s> void v_do_return(p_BOT pb)
  515.  * PURPOSE : Do a return
  516.  *         :
  517.  * CREATION: 11/29/1988 14:23:35
  518.  */
  519. void v_do_return(p_BOT pb)
  520. {
  521.    if (pb->depth<1) {
  522.       printf("RETURN without GOSUB\n");
  523.       exit(1);
  524.    }
  525.    pb->cline=pb->gosub[--pb->depth];
  526. } /* void v_do_return(p_BOT pb) */
  527.  
  528. /*<f>----------------------------------------
  529.  * FUNCTION: <s> void v_free_interpreter_ram(p_BOT p)
  530.  * PURPOSE : Free up ram allocated by interpreter
  531.  *         :
  532.  * CREATION: 12/05/1988 16:27:40
  533.  */
  534. void v_free_interpreter_ram(p_BOT p)
  535. {
  536. int a;
  537.  
  538.    for (a=0; a<MAXLINES; a++)
  539.       if (p->line[a]!=NULL)
  540.          free(p->line[a]);
  541. } /* void v_free_interpreter_ram(p_BOT p) */
  542.  
  543. /*<f>----------------------------------------
  544.  * FUNCTION: <s> void v_shoot(p_BOT p)
  545.  * PURPOSE : Fire a bullet in current direction
  546.  *         :
  547.  * CREATION: 12/05/1988 19:16:09
  548.  */
  549. void v_shoot(p_BOT p)
  550. {
  551.    switch (p->gdir) {
  552.       case 1 : v_init_bullet(p->bx,p->by,0,-2,BASERANGE);
  553.                break;
  554.       case 2 : v_init_bullet(p->bx+1,p->by,1,-2,BASERANGE);
  555.                break;
  556.       case 3 : v_init_bullet(p->bx+1,p->by,1,0,BASERANGE);
  557.                break;
  558.       case 4 : v_init_bullet(p->bx+1,p->by+3,1,2,BASERANGE);
  559.                break;
  560.       case 5 : v_init_bullet(p->bx,p->by+3,0,2,BASERANGE);
  561.                break;
  562.       case 6 : v_init_bullet(p->bx,p->by+3,-1,2,BASERANGE);
  563.                break;
  564.       case 7 : v_init_bullet(p->bx,p->by,-1,0,BASERANGE);
  565.                break;
  566.       case 8 : v_init_bullet(p->bx,p->by,-1,-2,BASERANGE);
  567.                break;
  568.    }
  569. } /* void v_shoot(p_BOT p) */
  570.  
  571. /*<f>----------------------------------------
  572.  * FUNCTION: <s> BOOL b_check_for_hit(int x, int y)
  573.  * PURPOSE : Check if point (x,y) hits a tank
  574.  *         :
  575.  * CREATION: 12/06/1988 09:21:46
  576.  */
  577. BOOL b_check_for_hit(int x, int y)
  578. {
  579. int a;
  580.  
  581.    a=1;
  582.    if (a==1) return FALSE; /* temp */
  583.  
  584.    if (field[x][y]==0) return FALSE;
  585.  
  586.    for (a=0; a<10; a++)
  587.       if (players[a].active)
  588.          if ((players[a].bx==x || players[a].bx+1==x) &&
  589.              (players[a].by==y || players[a].by+1==y || players[a].by+2==y || players[a].by+3==y)
  590.          ) return a+1;
  591.  
  592.    return FALSE;
  593. } /* BOOL b_check_for_hit(int x, int y) */
  594.  
  595. /*<f>----------------------------------------
  596.  * FUNCTION: <s> void v_flash_tank(int a)
  597.  * PURPOSE : Flash a tank after being hit
  598.  *         :
  599.  * CREATION: 12/06/1988 09:28:33
  600.  */
  601. void v_flash_tank(int a)
  602. {
  603. int b;
  604.  
  605.    if (!players[a].active) {
  606.       printf("HIT ERROR");
  607.       exit(1);
  608.    }
  609.  
  610.    for (b=0; b<5; b++) {
  611.       v_draw_player(&players[a]);
  612.       delay(50);
  613.       v_erase_player(&players[a]);
  614.       delay(20);
  615.    }
  616. } /* void v_flash_tank(int a) */
  617.  
  618. /*<f>----------------------------------------
  619.  * FUNCTION: <s> int n_check_radar(p_BOT p)
  620.  * PURPOSE : Look around for close tanks
  621.  *         : and return distance
  622.  * CREATION: 12/06/1988 11:49:48
  623.  */
  624. int n_check_radar(p_BOT p)
  625. {
  626. int f,d,a;
  627. int x,y;
  628.  
  629.    for (f=999, a=0; a<10; a++)
  630.       if (players[a].active && p!=&players[a]) {
  631.          x=abs(players[a].bax-p->bax);
  632.          y=abs(players[a].bay-p->bay);
  633.          x=x*x; y=y*y;
  634.          d=(int) sqrt((double)(x+y));
  635.          if (d<f) f=d;
  636.       }
  637.    return ((f==999) ? 0 : f);
  638. } /* int n_check_radar(p_BOT p) */
  639.  
  640. /*<f>----------------------------------------
  641.  * FUNCTION: <s> int n_check_scan(p_BOT p, int n)
  642.  * PURPOSE : Perform a scan for robot p in direction n
  643.  *         :
  644.  * CREATION: 12/06/1988 14:02:03
  645.  */
  646. int n_check_scan(p_BOT p, int n)
  647. {
  648. int dx,dy,a,adx, ady;
  649.  
  650.    for (a=0; a<10; a++)
  651.       if (players[a].active && p!=&players[a]) {
  652.  
  653.          dx=p->bax-players[a].bax;
  654.          dy=p->bay-players[a].bay;
  655.          adx=abs(dx);
  656.          ady=abs(dy);
  657.  
  658.          switch (n) {
  659.             case 1 : if ((dx==0) && (dy> 0)) return TRUE;
  660.                      break;
  661.             case 2 : if ((dx< 0) && (dy> 0) && (adx==ady)) return TRUE;
  662.                      break;
  663.             case 3 : if ((dx<0 ) && (dy==0)) return TRUE;
  664.                      break;
  665.             case 4 : if ((dx< 0) && (dy< 0) && (adx==ady)) return TRUE;
  666.                      break;
  667.             case 5 : if ((dx==0) && (dy< 0)) return TRUE;
  668.                      break;
  669.             case 6 : if ((dx> 0) && (dy< 0) && (adx==ady)) return TRUE;
  670.                      break;
  671.             case 7 : if ((dx> 0) && (dy==0)) return TRUE;
  672.                      break;
  673.             case 8 : if ((dx> 0) && (dy> 0) && (adx==ady)) return TRUE;
  674.                      break;
  675.          }
  676.       }
  677.       return FALSE;
  678. } /* int n_check_scan(p_BOT p, int n) */
  679.  
  680. /*<f>----------------------------------------
  681.  * FUNCTION: <s> void v_init_playfield(void)
  682.  * PURPOSE : Create playfield
  683.  *         :
  684.  * CREATION: 12/06/1988 14:44:58
  685.  */
  686. void v_init_playfield(void)
  687. {
  688.    memset(field,0,sizeof(field));
  689. } /* void v_init_playfield(void) */
  690.  
  691. /*<f>----------------------------------------
  692.  * FUNCTION: <s> void v_draw_player(p_BOT p)
  693.  * PURPOSE : Show player on screen
  694.  *         :
  695.  * CREATION: 12/06/1988 14:46:17
  696.  */
  697. void v_draw_player(p_BOT p)
  698. {
  699.    if (p->active) {
  700.       CALLASM(p->bx,p->by,p->pic[p->gdir]);
  701.       field[p->bax][p->bay]=1;
  702.    }
  703. } /* void v_draw_player(p_BOT p) */
  704.  
  705. /*<f>----------------------------------------
  706.  * FUNCTION: <s> void v_redraw_player(p_BOT p)
  707.  * PURPOSE : Redraw player on screen (Do not update field)
  708.  *         :
  709.  * CREATION: 12/06/1988 15:17:53
  710.  */
  711. void v_redraw_player(p_BOT p)
  712. {
  713.    if (p->active)
  714.       CALLASM(p->bx,p->by,p->pic[p->gdir]);
  715. } /* void v_redraw_player(p_BOT p) */
  716.  
  717. /*<f>----------------------------------------
  718.  * FUNCTION: <s> void v_erase_player(p_BOT p)
  719.  * PURPOSE : Erase player on screen
  720.  *         :
  721.  * CREATION: 12/06/1988 14:49:03
  722.  */
  723. void v_erase_player(p_BOT p)
  724. {
  725.    if (p->active) {
  726.       CALLASM(p->obx,p->oby,blank);
  727.       field[p->obax][p->obay]=0;
  728.    }
  729. } /* void v_erase_player(p_BOT p) */
  730.